Surface wavepackets subject to an abrupt depth change. Part 1. Second-order theory