1. When a criminal action is pending against a defendant who is confined in an institution within the state pursuant to a court order issued in a different action, proceeding or matter, the following courts and judges may, under the indicated circumstances, order that the defendant be produced in the court in which the criminal action is pending for purposes of arraignment or prosecution therein:
(a) If the action is pending in a superior court or with a superior court judge sitting as a local criminal court, or in a district court or the New York City criminal court, such court may, upon application of the district attorney, order the production therein of a defendant confined in any institution within the state.(b) If the action is pending in a city court or a town court or a village court, such court may, upon application of the district attorney, order production therein of a defendant confined in a county jail of such county. Production therein of a defendant confined in any other institution within the state may, upon application of the district attorney, be ordered by a judge of a superior court holding a term thereof in the county in which the action is pending.2. An application by a district attorney, pursuant to subdivision one, for production of a defendant confined in an institution located in another county in connection with a criminal action or proceeding pending in such other county, must be made upon reasonable notice to the district attorney of such other county and to the attorney representing such defendant in or in connection with the action or proceeding pending therein, and the court or judge must accord them reasonable opportunity to be heard in the matter. If such court or judge determines that production of the defendant would result in an unreasonable interference with the conduct of the action in such other county, it must deny the application. If an order of production is issued, a justice of the appellate division, of either the department embracing the county of issuance thereof or of the department embracing the county of the defendant’s confinement, upon application of the district attorney of the county of confinement or of the attorney representing the defendant in or in connection with the action pending therein, may for good cause shown vacate such order of production.