Lattice dynamics, dielectric properties and structural instabilities of SrTiO3 and BaTiO3