1. A method for tracking the motion of a device across a surface, the method comprising repeatedly performing the following steps (a)-(d): (a) acquiring, using an image sensor of the device, an input image showing an input area, the input area being a portion of the surface which is in the field of view of the image sensor; (b) comparing the input image to a plurality of current reference images showing respective current reference areas of the surface to estimate the displacement between the input area and each current reference area, wherein the plurality of current reference images comprise previously acquired images; (c) determining whether to update each individual current reference image based on the displacements estimated in step (b), and if said determination is positive for an individual current reference image, updating the individual current reference image to form an updated reference image; and (d) determining, based on the displacements, the motion of the device across the surface from an area shown in a previously acquired image to the input area; wherein prior to step (d) in each repetition of steps (a)-(d), the method further comprises improving one or more of the displacements estimated in step (b) by: (i) determining the displacement between each current reference area and each of the other current reference areas using the current reference images; (ii) determining improved estimates of the displacements estimated in step (b), by minimizing a function of differences between the displacements determined in step (i) and corresponding displacements determined with the improved estimates; and (iii) improving the one or more of the displacements by setting these displacements as their respective improved estimates.