Java Stack Overflow Error Recursive Function In Python