Fix calculation of num ref frames