Section 47. The court, if satisfied that there is good cause to believe that a witness will not perform the condition of his recognizance unless other security is given, may order the witness to enter into a recognizance with such sureties as the court deems necessary for his appearance at court; provided that the witness shall be entitled to be present and to be represented by counsel at a hearing before the court, at which hearing the witness shall be entitled to be heard on the issue of the alleged materiality of his testimony, and on the issue of recognizance with or without surety.