For a first comparison, divide the upfront costs of switching by the monthly saving. Then check that both loans have comparable lengths and remaining balances.
An example with numbers
If switching your mortgage costs $2,400 and lowers the payment by $80 a month, the simple payback period is 30 months. If you plan to sell in 18 months, the accumulated saving would be $1,440, less than the upfront cost.
Try it with your numbers
Write down costs, payments, terms and the debt remaining on the day you expect to sell. A lower payment obtained by extending the term needs an extra comparison.
This calculator is on its way. In the meantime, you can do the calculation on paper or in a spreadsheet.
Example figures for learning purposes. They are not a recommendation and do not replace professional advice.