Windowed Green function method for the Helmholtz equation in the presence of multiply layered media