Dynamic mechanism of polaron pairing in a two-layer model for high-Tc oxides