Korteweg-de Vries equation with finite-gap boundary conditions, and the Whitham deformations of Riemann surfaces