Oxygen-isotope effect in the optical conductivity of YBa2Cu3Oy and Bi2Sr2CaCu2O8+δ