Envelope function method for electrons in slowly-varying inhomogeneously deformed crystals