Okla. Stat. tit. 12, § 12-395
Discharge when imprisonment illegal
A witness so imprisoned by an officer before whom his deposition
is being taken, may apply to a judge of a court of record, who shall
have power to discharge him, if it appears that his imprisonment is
illegal.
R.L. 1910, § 5060.