The effect of annealing on the refractive index and the optical uniformity of undoped and phosphorus doped SiO2 films on silicon and quartz substrates is studied. The films are grown using low-pressure chemical vapour deposition. Vertical homogeneity of the refractive index is shown to be a relevant measure upon optimizing the annealing treatment for the film. High temperature annealing results in a decrease of the refractive index and an increase in the inhomogeneity of the refractive index in the vertical direction. This is due to the outdiffusion of phosphorus as well as the reduction of compressive stresses in the films. Stresses have also been considered to be the main reason for the refractive index difference of the order of 10-3 between films grown on silicon and on quartz substrates.