Or a completely different approach.
In[1]:= rectangles={{25,22},{40,28},{25,22},{31,23},{31,23},{40,28},{40,28},{25,22},{25,22},{31,23},{31,23},{31,23},{40,28}};
splitIntoRows[rows_, {}] := rows;
splitIntoRows[rows_,{Longest[row__]/;First[Total[{row}]]<=130,rects___}]:=splitIntoRows[Append[rows,{row}],{rects}];
rows = splitIntoRows[{}, rectangles]
Out[4]= {
{{25, 22}, {40, 28}, {25, 22}, {31, 23}},
{{31, 23}, {40, 28}, {40, 28}},
{{25, 22}, {25, 22}, {31, 23}, {31, 23}},
{{31, 23}, {40, 28}}}
Same study and testing.