Brooklyn teachers wrongly fired after sex allegations, court rules