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 current reference image based on the displacements estimated in step (b), and if said decision is positive, updating the 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.