How can I fix this problem with duplicate index in 4.7.21?
You can apply this PR - and reload System status page. This will let you know in advance which indices are already present in DB and would result in DB error on hitting Update Indices button. So what need to be done is -


Apply this PR.
Reload System status page.
Some duplicate indices would be shown above Update Indices button including a message of what needs to be done.
Delete indices manually from the DB (which are listed on above step). 
Execute Update Indices button.


Update: just saw the error again - So the error say you have two rows which contain the same values for (entity_id, entity_table, account_relationship) as 5, civicrm_financial_type and 3 respectively. This should not be there as this group of fields are meant to be unique. To remove this error, you can -


Open civicrm_entity_financial_account table.
Search for rows that match entity_id = 5, entity_table = civicrm_financial_type and account_relationship = 3. You'll get two rows(This table should allow only one after indexing), delete one of them and re-execute Update Indices button. This is not provided by core as of now, so we have to do this manually.