Selling a matching number of shares by the end of the year doesn’t avoid a wash sale. In the right circumstances, it may give you the same result as if a wash sale had not occurred, but you still have to report a wash sale and make the appropriate adjustment as to the shares you sold later.
The wash sale regulations have matching rules that generally require us to work chronologically when there are multiple batches that can be paired with a single sale. Unfortunately, in your example this would mean the shares that match are the 500 ISO shares you bought on 8/1 and 100 of the ISO shares you bought on 8/5. According to those regs, the wash sale adjustment (added basis) would apply to those shares, and you would have to sell those shares to get the resulting loss. Doing this by the end of the year would require you to forgo the potential tax benefit of holding ISO shares.