Section 38. The court or justice before whom a person is taken upon a charge of crime shall, as soon as may be, examine on oath the complainant and the witnesses for the prosecution, in the presence of the defendant, relative to any material matter connected with such charge. After the testimony to support the prosecution, the witnesses for the prisoner, if any, shall be examined on oath, and he may be assisted by counsel in such examination and in the cross examination of the witnesses in support of the prosecution. Nothing contained herein shall be construed to prohibit the enforcement of the waiver provisions of Rule 3 of the Massachusetts Rules of Criminal Procedure. A defendant charged with an offense as to which he has the right to be proceeded against by indictment may elect a probable cause hearing in accordance with Rule 3 of the Massachusetts Rules of Criminal Procedure, but in such event shall be deemed to have waived his right to be proceeded against by indictment.