I'm certainly not saying the sailing-ship answer is wrong, but the phrase appeared nowhere in print prior to the mid-20th century. That strikes me as being rather late, plus it first appeared as 'lean over backwards' in the USA. Given Britain's long naval traditions and centuries of sea-tales, you'd think it would have appeared much earlier. As for its meaning, the suggestion is that there is an element of inconvenience involved in the effort to help someone...ie you're 'going out of your way' to assist. Also, there is often the idea of going to the opposite extreme in order to avoid any suggestion of bias against the person being helped. Sometimes there is even a notion that you are going almost too far in an effort to overcome your natural 'inclination' perhaps not to help.