This is a logic problem, not a code problem. First of all, I suggest printing out the value of length at each recursion. That will hopefully reveal the problem. You could even do this by hand and see the problem.
Overall, you are treating the variable length inconsistently. Before the recursion, you correctly subtract 1 to get the zero-based-index position of the last character. But then you decrease length by 2 as you start the recursion, even though you have retrieved only 1 character from the end. Right there you changed the meaning of length to mean the last position instead of the length of the remaining string. But inside maximum() you treat it like the string length in one part of the code and like the last position in another part.
Either way, you need to change the code inside maximum() to treat the variable consistently. Depending on what meaning you choose, you may need to change the argument values that you initially send to maximum().