Index: /trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java	(revision 18236)
+++ /trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java	(revision 18237)
@@ -273,11 +273,12 @@
             // This code gives a simple linear interpolation of the coordinates between current and
             // previous track point assuming a constant speed in between
+            LatLon nextCoorForDirection = nextWp != null ? nextWp.getCoor() : null;
             while (i >= 0) {
                 final GpxImageEntry curImg = images.get(i);
-                final GpxImageEntry curTmp = curImg.getTmp();
                 final long imgTime = curImg.getExifInstant().toEpochMilli();
                 if (imgTime < prevWpTime) {
                     break;
                 }
+                final GpxImageEntry curTmp = curImg.getTmp();
                 if (!curTmp.hasNewGpsData()) {
                     // The values of timeDiff are between 0 and 1, it is not seconds but a dimensionless variable
@@ -287,6 +288,6 @@
                     final LatLon curCoor = curWp.getCoor();
                     LatLon position = prevCoor.interpolate(curCoor, timeDiff);
-                    if (nextWp != null && (shiftXY || dirpos.isSetImageDirection())) {
-                        double direction = curCoor.bearing(nextWp.getCoor());
+                    if (nextCoorForDirection != null && (shiftXY || dirpos.isSetImageDirection())) {
+                        double direction = position.bearing(nextCoorForDirection);
                         if (dirpos.isSetImageDirection()) {
                             curTmp.setExifImgDir(computeDirection(direction, dirpos.getImageDirectionAngleOffset()));
@@ -311,4 +312,5 @@
                     curImg.tmpUpdated();
 
+                    nextCoorForDirection = curCoor;
                     ret++;
                 }
