Section 23. Detention. No person shall be imprisoned for the purpose of securing his testimony in any criminal proceeding longer than may be necessary in order to take his deposition. If he can give security for his appearance at the time of trial, he shall be discharged upon giving the same; if he cannot give security, his deposition shall be taken in the manner provided by law, and in the presence of the accused and his counsel, or without their presence, if they shall fail to attend the examination after reasonable notice of the time and place thereof.