Diffuse galactic gamma rays at intermediate and high latitudes. I. Constraints on the ISM properties